#include "Lift_motor.h"

void LM_init(){
    EAXSFR();	
	LM_GPIO();
}

void LM_move(int speed) {
    PWMx_InitDefine		PWMx_InitStructure;

    int duty = Speed_To_Duty(speed);

		// 配置PWM4	
		PWMx_InitStructure.PWM_Mode    			= CCMRn_PWM_MODE1;								//模式,		CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
		PWMx_InitStructure.PWM_Duty    			= PERIOD * duty / 100;						//PWM占空比时间, 0~Period
		PWMx_InitStructure.PWM_EnoSelect    = duty != 50 ? ENO4P | ENO4N : 0;	//输出通道选择,	ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8P
		PWM_Configuration(PWM4, &PWMx_InitStructure);

	
	
		// 配置PWMA
    PWMx_InitStructure.PWM_Period   = PERIOD - 1;			//周期时间,   0~65535
    PWMx_InitStructure.PWM_DeadTime = 2;					//死区发生器设置, 0~255
    PWMx_InitStructure.PWM_MainOutEnable= ENABLE;			//主输出使能, ENABLE,DISABLE
    PWMx_InitStructure.PWM_CEN_Enable   = ENABLE;			//使能计数器, ENABLE,DISABLE
    PWM_Configuration(PWMA, &PWMx_InitStructure);			//初始化PWM通用寄存器,  PWMA,PWMB

    PWM4_SW(PWM4_SW_P16_P17);	
}

void LM_stop(){
    LM_move(0);
}